mui.init({
 
});

var old_back = mui.back;
mui.back = function(){
//	var targetPageId = plus.storage.getItem(KeyCfg.targetPageId);	
//	if(!targetPageId){
//		mui.alert("参数：targetPageId 为 null ,无法跳转到下一步");
//		return;
//	}
//	var targetPage = plus.webview.getWebviewById(targetPageId);
//  mui.fire(targetPage,'reload',{});
//  targetPage.show();
    var page=mui.currentWebview.opener();
	page.show();
	mui.fire(page,'reload',{});
	//继续当前页面原有返回逻辑
	old_back();
}


mui.plusReady(function() {
	var guid = plus.webview.currentWebview().guid;
	$("#guid").val(guid);
	
	var sub = CmwMcore.$('sub');
	MeventMgr.onTouchstart(sub,function(event,self){					
			if(!valid()) return;			
//			submitForm();
	});		
	
	/*表单验证*/
	function valid(){
			var bankCity = $("#bankCity").val();	//开户城市
			var bankName = $("#bankName").val();//开户行
			var payPassword = $("#payPassword").val();//支付密码
			var a = document.getElementById("bankCardNumber");
			if (!bankCity || bankCity.trim() == null || bankCity.trim().length == 0 ){
				mui.alert("开户城市不能为空!");
				return false;
			}
			
			if (!bankName ){
				mui.alert("开户行不能为空!");
				return false;
			}
			
			if (payPassword && payPassword.trim() != null && payPassword.trim().length > 0){
				var param = {"payPassword": payPassword};
				var url=UrlConfig.mybank_checkPay;
				$.ajax({
					type : "POST",
					url : url,
					data : param,
					dataType : "jsonp",
					success : function(data) {
						data = JSON.parse(data);
						if (data.success){
							submitForm();
						}else{
							mui.alert(data.msg);
							return false;
						}
						
					}
				});
			}else{
				mui.alert("支付密码不能为空!");
				return false;
			}
		return true;
	}
	
	function submitForm(){
		var formDatas = $("#eidtBankCardForm").serialize();
		CmwMcore.disabled('sub');
		var url = UrlConfig.mybank_bankUpdate; 
		MuiEventMgr.ajax(url,{pars:formDatas,
		  	sfn : function(data){  	
		  		CmwMcore.enabled('sub');
	        		if (data.success){
	        			mui.alert(data.msg);
	        			forward();
				}else{
					mui.alert(data.msg);
				}
		  	},ffn : function(err){
		  		CmwMcore.enabled('sub');
		  		mui.alert("获取数据失败：["+err+"]");
		  	}
		 });
	}
	
	function forward(){
		mui.back();
//		var targetPageId = plus.storage.getItem(KeyCfg.targetPageId);
//		if(!targetPageId){
//			mui.alert("参数：targetPageId 为 null ,无法跳转到下一步");
//			return;
//		}
//		var targetPage = plus.webview.getWebviewById(targetPageId);
//	    mui.fire(targetPage,'reload',{});
//	    targetPage.show();
	}
});